#ifndef _OMDCL_MACHINE_HPP_
#define _OMDCL_MACHINE_HPP_

#include <iostream>
#include <string>
#include <vector>
#include <omd/toolkit.hpp>
#include <omd/paramhandler.hpp>
#include <CL/cl.h>

class MDComputeMachine: public MDToolkit {
friend class MDComputeProgram;
protected:
	cl_device_id device;
	cl_context context;
	cl_command_queue queue;
	
	struct MemSizes {
			unsigned long global;
			unsigned long local;
			unsigned long constant;
			unsigned long maxalloc;
			unsigned int address;
	} memsize;

	void CollectDeviceInfo();
	void Create();
	

public:
	ParamHandler param;

	MDComputeMachine(); // use first available machine...
	MDComputeMachine(string macname); // select a machine by name
	MDComputeMachine(cl_device_type mactype); // select the first machine matched type... 
        
	virtual ~MDComputeMachine();
	
	void Wait();
	void Wait(cl_event& evt);
	void Wait(int nevt, cl_event* evts);
	
	void PrintInfo(ostream& ost);
	
	cl_mem LoadTable(void* buf, size_t len);
	cl_mem CreateBuffer(size_t len, cl_mem_flags flag=CL_MEM_WRITE_ONLY);
	void   Extract(cl_mem devmem, void* hostmem, size_t len);
	void Release(cl_mem mem);


	static std::vector<std::string> GetDeviceList();

};

#endif
